package demo.bocweb.com.sdk.baseApi;

import demo.bocweb.com.sdk.base.bean.BaseBean;
import demo.bocweb.com.sdk.util.AppUtils;
import demo.bocweb.com.sdk.util.ToastUtils;
import io.reactivex.functions.Consumer;

/**
 * Created by zhelun on 2018/1/26.
 */

public abstract class BaseObserver<T> implements Consumer<T> {


    public abstract void setData(T t);

    @Override
    public void accept(T t) throws Exception {

        if (t instanceof BaseBean) {
            if (((BaseBean) t).getReturnCode() == 401 || ((BaseBean) t).getReturnCode() == 0011) {
                ToastUtils.showToast(((BaseBean) t).getMsg());
                //退出登录
                AppUtils.loginOut();
            } else {
                setData(t);
            }
        }
    }
}
